package net.poemcode.gzlib;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;

public class LibraryOpenHelper extends SQLiteOpenHelper {
	
    public static final String TABLE_NAME_LIB = "lib";
    public static final String TABLE_NAME_LOCAL = "local";
    public static final String TABLE_NAME_CIR = "cir";
    public static final String TABLE_NAME_STATE = "state";
    
    public static final String URI_AUTHORITY = "net.poemcode.gzlib.libraryprovider";
    public static final Uri CONTENT_URI_LIB = Uri.parse("content://" + URI_AUTHORITY + "/" + TABLE_NAME_LIB);
    public static final Uri CONTENT_URI_LOCAL = Uri.parse("content://" + URI_AUTHORITY + "/" + TABLE_NAME_LOCAL);
    public static final Uri CONTENT_URI_CIR = Uri.parse("content://" + URI_AUTHORITY + "/" + TABLE_NAME_CIR);
    public static final Uri CONTENT_URI_STATE = Uri.parse("content://" + URI_AUTHORITY + "/" + TABLE_NAME_STATE);

    public static final String COLUMN_CODE = "code";
    public static final String COLUMN_NAME = "name";
    
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "gzlibrary.db";
    
	public LibraryOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + TABLE_NAME_LIB + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, code TEXT unique, name TEXT not null);");
		db.execSQL("CREATE TABLE " + TABLE_NAME_LOCAL + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, code TEXT unique, name TEXT not null);");
		db.execSQL("CREATE TABLE " + TABLE_NAME_CIR + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, code TEXT unique, name TEXT not null);");
		db.execSQL("CREATE TABLE " + TABLE_NAME_STATE + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, code TEXT unique, name TEXT not null);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// 暂时用不到
	}

}
